package com.jerry.constellation.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.jerry.constellation.Adapter.DetailsBaseAdapter;
import com.jerry.constellation.R;
import com.jerry.constellation.Utils.AssetsUtils;
import com.jerry.constellation.bean.StarInfoBean;
import com.jerry.constellation.bean.StardetialsBean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;

public class StardetailsActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView titleTV;
    private ImageView backIv;
    private CircleImageView icnoIv;
    private TextView nameTv;
    private TextView timeTv;
    private ListView containsLv;
    private StarInfoBean.StarinfoBean bean;
    private TextView footer_Tv;//listview底部footer中的TV
    private List<StardetialsBean> mdata;
    private DetailsBaseAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_stardetails);
        initview();
        initData();
        initMdata();

    }

    private void initMdata() {
        mdata = new ArrayList<>();//初始化ListView的数据源
        adapter = new DetailsBaseAdapter(StardetailsActivity.this, mdata);
        containsLv.setAdapter(adapter);
        addDataToList();
    }

    /*
     * 加载Listview当中的数据源内容
     * */
    private void addDataToList() {
        StardetialsBean sdb1 = new StardetialsBean("性格特点：", bean.getTd(), R.color.lightblue);
        StardetialsBean sdb2 = new StardetialsBean("掌管宫位：", bean.getGw(), R.color.lightpink);
        StardetialsBean sdb3 = new StardetialsBean("显阴阳性：", bean.getYy(), R.color.lightgreen);
        StardetialsBean sdb4 = new StardetialsBean("最大特征：", bean.getTz(), R.color.purple);
        StardetialsBean sdb5 = new StardetialsBean("主管星球：", bean.getZg(), R.color.orange);
        StardetialsBean sdb6 = new StardetialsBean("幸运颜色：", bean.getYs(), R.color.colorAccent);
        StardetialsBean sdb7 = new StardetialsBean("搭配珠宝：", bean.getZb(), R.color.colorPrimary);
        StardetialsBean sdb8 = new StardetialsBean("幸运数字：", bean.getHm(), R.color.grey);
        StardetialsBean sdb9 = new StardetialsBean("相配金属：", bean.getJs(), R.color.darkblue);
        mdata.add(sdb1);
        mdata.add(sdb2);
        mdata.add(sdb3);
        mdata.add(sdb4);
        mdata.add(sdb5);
        mdata.add(sdb6);
        mdata.add(sdb7);
        mdata.add(sdb8);
        mdata.add(sdb9);
        //数据源发送变化时，提示适配器更新
        adapter.notifyDataSetChanged();
    }

    private void initData() {
        //获取数据
        Intent intent = getIntent();
        bean = (StarInfoBean.StarinfoBean) intent.getSerializableExtra("star");
        //开始设置
        nameTv.setText(bean.getName());
        timeTv.setText(bean.getDate());
        Map<String, Bitmap> contentlogimgMap = AssetsUtils.getContentlogimgMap();
        Bitmap bitmap = contentlogimgMap.get(bean.getLogoname());
        icnoIv.setImageBitmap(bitmap);
        footer_Tv.setText(bean.getInfo());
    }

    private void initview() {
        titleTV = findViewById(R.id.title_tv);
        backIv = findViewById(R.id.title_iv_back);
        icnoIv = findViewById(R.id.stardetails_iv);
        nameTv = findViewById(R.id.stardetails_tv_name);
        timeTv = findViewById(R.id.stardetails_tv_time);
        containsLv = findViewById(R.id.stardetails_lv);

        //初始化设置
        timeTv.setText("星座详情");
        backIv.setOnClickListener(this);
        //加载底部布局
        View footerview = LayoutInflater.from(this).inflate(R.layout.footerbar_layout, null);
        containsLv.addFooterView(footerview);
        footer_Tv = footerview.findViewById(R.id.footer_tv_info);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_iv_back:
                finish();
                break;
            default:
                break;
        }
    }
}